

#ifndef __MALLOC_H__
#define __MALLOC_H__

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>

#ifdef __cplusplus
extern "C"
{
#endif
//==================================================================================================
size_t heap_total_free_min(void);
size_t heap_total_free(void);

void * aligned_malloc(size_t alignment, size_t size);
void aligned_free(void *p);

/**
 * heap trace api
*/
#define malloc_trace(size) \
    ({ void *p = malloc(size); heap_log_trace("malloc:%p[%zu]", p, size); p; })

#define calloc_trace(count, size) \
    ({ void *p = calloc(count,size); heap_log_trace("calloc:%p[%zu]", p, count * size); p; })

#define realloc_trace(ptr, newsize) \
    ({ void *p = realloc(ptr, newsize); heap_log_trace("realloc:%p->%p[%zu]", ptr, p, newsize); p; })

#define aligned_alloc_trace(alignment, size) \
    ({ void *p = aligned_alloc(alignment, size); heap_log_trace("aligned_alloc:%p[%zu]", p, size); p; })

#define free_trace(p) \
    do{ free(p); heap_log_trace("free:%p", p); }while(0)
//==================================================================================================
#ifdef __cplusplus
}
#endif
#endif //__MALLOC_H__
//==================================================================================================
//end files
